import { reactive } from "vue";
import type {
    FormRules
} from "element-plus";

// 定义商品信息的类型
export interface Products {
    id: number;
    icon: string[];
    productTitle: string;
    price: number|undefined;

    brand: string;
    sst: string[];
    soleMaterial: string;
    functionality: string[];
    upperHeight: string;
    applicableCrowd: string;
    upperMaterial: string;
    sportsSeries: string;
    applicableVenues: string;
    craftsmanship: string;
    marketSeason: string;
}

// 将对象中string转换array
export const stringOnArray = (product: any) => {
    let productObj: Products = product;
    productObj.icon = product.icon.split("，");
    productObj.sst = product.sst.split("，");
    productObj.functionality = product.functionality.split("，");
    return productObj;
}

// 将对象中array转换string
export const arrayOnString = (product: Products) => {
    let productObj: any = product;
    productObj.icon = product.icon.join("，");
    productObj.sst = product.sst.join("，");
    productObj.functionality = product.functionality.join("，");
    return productObj;
}

// 抽屉状态管理
export const drawerManage = {
    details: false,
    updata: false
}

// 列表筛选: 鞋帮高度
export const upperHeight = [
    { text: '高帮', value: '高帮' },
    { text: '低帮', value: '低帮' },
]


// 表单提交校验
export const rules = reactive<FormRules<Products>>({
    productTitle: [{ required: true, message: "输入商品标题", trigger: "blur" }],
    price: [
        {
            required: true,
            message: "输入商品价格",
            trigger: "change",
        },
    ],
    brand: [
        {
            required: true,
            message: "输入商品品牌",
            trigger: "change",
        },
    ],
    marketSeason: [
        {
            required: true,
            message: "输入商品上市季节",
            trigger: "change",
        },
    ],
    sst: [
        {
            type: "array",
            required: true,
            message: "选择商品科技",
            trigger: "change",
        },
    ],
    soleMaterial: [
        {
            required: true,
            message: "选择商品鞋底材质",
            trigger: "change",
        },
    ],
    functionality: [
        {
            required: true,
            message: "选择商品功能特性",
            trigger: "change",
        },
    ],
    upperHeight: [
        {
            required: true,
            message: "选择商品鞋帮高度",
            trigger: "change",
        },
    ],
    upperMaterial: [
        {
            required: true,
            message: "选择商品鞋面材质",
            trigger: "change",
        },
    ],
    applicableVenues: [
        {
            required: true,
            message: "选择商品适用场地",
            trigger: "change",
        },
    ],
    craftsmanship: [
        {
            required: true,
            message: "选择商品制作工艺",
            trigger: "change",
        },
    ],
});